from flask import Flask
from config import config
from initiate import register_blueprints, register_log, register_middleware, register_exception, register_commands, \
    register_extensions, register_heartbeat_to_nacos
from utils.config import get_config


def create_app():
    app = Flask(__name__)
    env = get_config('FLASK_ENV')
    secret_key = get_config('secret_key')
    SERVICE_PORT = get_config('SERVICE_PORT')
    app.config.from_object(config[env])
    app.config['SECRET_KEY'] = secret_key
    register_blueprints(app)
    register_log(app)
    register_middleware(app)
    register_exception(app)
    register_commands(app)
    register_extensions(app)
    register_heartbeat_to_nacos()
    app.run(port=SERVICE_PORT, debug=True)
    return app


if __name__ == '__main__':
    app = create_app()
